package com.fenghongzhang.day004;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class Main2Activity extends AppCompatActivity {
    private Button btn;
    private static final String TAG = "Main2Activity";
    private ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);




        btn = (Button) findViewById(R.id.btn);
        img = (ImageView) findViewById(R.id.img);

    }

    public void btn10(View view) {

        ObjectAnimator animator = ObjectAnimator.ofFloat(img, "alpha", 0, 1, 0, 1);
        animator.setDuration(200);
        animator.setRepeatCount(2);
        animator.setInterpolator(new LinearInterpolator());


        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                Log.i(TAG, "onAnimationStart: ");
            }

            @Override
            public void onAnimationEnd(Animator animation) {

            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

        animator.start();


//        ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 1000);
//
//        valueAnimator.setRepeatCount(1);
//        valueAnimator.setDuration(1000);
//
//        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
//            @Override
//            public void onAnimationUpdate(ValueAnimator animation) {
//                int animatedValue = (int) animation.getAnimatedValue();
//                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) img.getLayoutParams();
//
//                layoutParams.leftMargin = animatedValue;
//
//                img.setLayoutParams(layoutParams);
//
//                img.requestLayout();
//
//            }
//        });
//        valueAnimator.start();
    }
}
